/**
 * 
 */
package com.dingjian.meal.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingjian.base.dao.BaseDao;
import com.dingjian.base.service.impl.BaseServiceImpl;
import com.dingjian.meal.dao.DishesDao;
import com.dingjian.meal.dao.MealRecordDao;
import com.dingjian.meal.model.Dishes;
import com.dingjian.meal.model.MealRecord;
import com.dingjian.meal.service.MealRecordService;

/**
 *
 * @author FengMy
 * @since 2012-6-8
 */
@Component(value="mealRecordService")
@Transactional
public class MealRecordServiceImpl extends BaseServiceImpl<MealRecord> implements
		MealRecordService {
	@Resource(name="mealRecordDao")
	private MealRecordDao mealRecordDao;
	@Resource(name="dishesDao")
	private DishesDao dishesDao;
	
	@Override
	protected BaseDao getDao() {
		return mealRecordDao;
	}
	@Override
	public void addEntity(MealRecord record) {
		Dishes d = dishesDao.getEntityById(record.getDishes().getId());
		record.setMoney(d.getPrice());
		super.addEntity(record);
	}

	@Override
	public void updateEntity(MealRecord record) {
		Dishes d = dishesDao.getEntityById(record.getDishes().getId());
		record.setMoney(d.getPrice());
		super.updateEntity(record);
	}


	public List<Map<String, Object>> summary(Map<String, Object> param) {
		return mealRecordDao.summary(param);
	}

	public boolean exists(Map<String, Object> param) {
		return mealRecordDao.exists(param);
	}
}
